--广播时间转发器 解耦MVC工具
EventListener = {}
local self = EventListener
self.events = {}

--添加监听事件
function self:Listener(name, call)
    local event = self.events[name]
    if event == nil then
        event = {
            calls = {}
        }
        self.events[name] = event
    end
    table.insert(event.calls, call)
    return call
end

--解除监听事件
function self:Remove(name, call)
    local event = self.events[name]
    if event then
        event[call] = nil
    end
end

--广播监听事件
function self:Broadcast(name, args)
    local event = self.events[name]
    if event then
        for k, call in pairs(event.calls) do
            call(args)
        end
    end
end

return self
